//
//  ActivityTableViewCell.m
//  Fengly_Nuo_Movie
//
//  Created by dllo on 15/12/31.
//  Copyright © 2015年 Fengly_Nuo. All rights reserved.
//

#import "ActivityTableViewCell.h"
#import "ActivityModel.h"
#import "UIImageView+WebCache.h"

// MARK:VIEW_CENTER_X:屏中心x轴
#define VIEW_CENTER_X self.contentView.center.x

// MARK:VIEW_CENTER_Y:屏中心y轴
#define VIEW_CENTER_Y self.contentView.center.y

// MARK:HEIGHT:屏高
#define HEIGHT self.contentView.frame.size.height

// MARK:WIDTH:屏宽
#define WIDTH self.contentView.frame.size.width

#define TITLEVIEW_WIDTH _titleView.frame.size.width
#define TITLEVIEW_HEIGHT _titleView.frame.size.height

#define INFORVIEW_WIDTH _infoView.frame.size.width
#define INFORVIEW_HEIGHT _infoView.frame.size.height

@interface ActivityTableViewCell ()

@property (nonatomic, retain) UIView *titleView;
@property (nonatomic, retain) UIView *infoView;
@property (nonatomic, retain) UIImageView *viewImage; /**< 最下面view的图 */
@property (nonatomic, retain) UIImageView *timeImage; /**< time image */
@property (nonatomic, retain) UIImageView *addressImage; /**< address image */
@property (nonatomic, retain) UIImageView *category_nameImage; /**< category_name image */
@property (nonatomic, retain) UIImageView *image; /** image images */

@property (nonatomic, retain) UILabel *titleLabel; /**< title label */
@property (nonatomic, retain) UILabel *timeLabel; /**< time label */
@property (nonatomic, retain) UILabel *addressLabel; /**< address label */
@property (nonatomic, retain) UILabel *category_nameLabel; /**< category_name label */
@property (nonatomic, retain) UILabel *interestLabel; /**< interest label */
@property (nonatomic, retain) UILabel *interestNumLabel; /**< interest number label */
@property (nonatomic, retain) UILabel *joinLabel; /**< join label */
@property (nonatomic, retain) UILabel *joinNumLabel; /**< join number label */

@end

@implementation ActivityTableViewCell

- (void)setModel:(ActivityModel *)model {
    if (_model != model) {
        [_model release];
        _model = [model retain];
        
        [self assignment];
    }
}

- (void)assignment {
    _viewImage.image = [UIImage imageNamed:@"bg_eventlistcell2.png"];
    
    _timeImage.image = [UIImage imageNamed:@"icon_date.png"];
    _addressImage.image = [UIImage imageNamed:@"icon_spot.png"];
    _category_nameImage.image = [UIImage imageNamed:@"icon_catalog.png"];
    
    
    [_image sd_setImageWithURL:[NSURL URLWithString:_model.image]];
    
    _titleLabel.text = _model.title;
    _titleLabel.font = [UIFont boldSystemFontOfSize:20];
    
    NSString *begin_Str = [_model.begin_time substringWithRange:NSMakeRange(5, 11)];
    NSString *end_Str = [_model.end_time substringWithRange:NSMakeRange(5, 11)];
    NSString *begin_End_str = [NSString stringWithFormat:@"%@ -- %@", begin_Str, end_Str];
    _timeLabel.text = begin_End_str;
    
    _addressLabel.text = _model.address;
    
    _category_nameLabel.text = _model.category_name;
    
    _interestLabel.text = @"感兴趣：";
    _interestLabel.font = [UIFont systemFontOfSize:14];
    NSString *wish_count_str = [NSString stringWithFormat:@"%@", _model.wisher_count];
    _interestNumLabel.text = wish_count_str;
    [_interestNumLabel setTextColor:[UIColor redColor]];
    _interestNumLabel.font = [UIFont systemFontOfSize:14];
    
    _joinLabel.text = @"参加：";
    _joinLabel.font = [UIFont systemFontOfSize:14];
    NSString *participant_str = [NSString stringWithFormat:@"%@", _model.participant_count];
    _joinNumLabel.text = participant_str;
    [_joinNumLabel setTextColor:[UIColor redColor]];
    _joinNumLabel.font = [UIFont systemFontOfSize:14];
}




- (void)dealloc {
    [_timeImage release];
    [_addressImage release];
    [_category_nameImage release];
    [_viewImage release];
    [_titleView release];
    [_titleLabel release];
    [_infoView release];
    [_category_nameLabel release];
    [_timeLabel release];
    [_addressLabel release];
    [_image release];
    [_interestLabel release];
    [_interestNumLabel release];
    [_joinLabel release];
    [_joinNumLabel release];
    [_model release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createActivityCell];
    }
    return self;
}

- (void)createActivityCell {
    self.titleView = [[UIView alloc] init];
    [self.contentView addSubview:_titleView];
    [_titleView release];
    
    self.viewImage = [[UIImageView alloc] init];
    [_titleView addSubview:_viewImage];
    [_viewImage release];
    
    self.infoView = [[UIView alloc] init];
    [_titleView addSubview:_infoView];
    [_infoView release];
    
    self.titleLabel = [[UILabel alloc] init];
    [_titleView addSubview:_titleLabel];
    [_titleLabel release];
    
    self.timeImage = [[UIImageView alloc] init];
    [_infoView addSubview:_timeImage];
    [_timeImage release];
    
    self.addressImage = [[UIImageView alloc] init];
    [_infoView addSubview:_addressImage];
    [_addressImage release];
    
    self.category_nameImage = [[UIImageView alloc] init];
    [_infoView addSubview:_category_nameImage];
    [_category_nameImage release];
    
    self.timeLabel = [[UILabel alloc] init];
    [_infoView addSubview:_timeLabel];
    [_timeLabel release];
    
    self.addressLabel = [[UILabel alloc] init];
    [_infoView addSubview:_addressLabel];
    [_addressLabel release];
    
    self.category_nameLabel = [[UILabel alloc] init];
    [_infoView addSubview:_category_nameLabel];
    [_category_nameLabel release];
    
    self.image = [[UIImageView alloc] init];
    [_infoView addSubview:_image];
    [_image release];
    
    self.interestLabel = [[UILabel alloc] init];
    [_infoView addSubview:_interestLabel];
    [_interestLabel release];
    
    self.interestNumLabel = [[UILabel alloc] init];
    [_infoView addSubview:_interestNumLabel];
    [_interestNumLabel release];
    
    self.joinLabel = [[UILabel alloc] init];
    [_infoView addSubview:_joinLabel];
    [_joinLabel release];
    
    self.joinNumLabel = [[UILabel alloc] init];
    [_infoView addSubview:_joinNumLabel];
    [_joinNumLabel release];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    _titleView.frame = CGRectMake(10, 10, WIDTH - 20, 200);
    _titleView.layer.cornerRadius = 10;
    
    _viewImage.frame = CGRectMake(0, 0, TITLEVIEW_WIDTH, TITLEVIEW_HEIGHT);
    
    _infoView.frame = CGRectMake(2, 40, TITLEVIEW_WIDTH - 4, TITLEVIEW_HEIGHT - 50);
    _infoView.backgroundColor = [UIColor whiteColor];
    _infoView.layer.cornerRadius = 5;
    
    _titleLabel.frame = CGRectMake(2, 0, TITLEVIEW_WIDTH, 40);
//    _titleLabel.font = [UIFont boldSystemFontOfSize:20];
    
    _timeImage.frame = CGRectMake(5, 10, 20, 20);
    
    _addressImage.frame = CGRectMake(5, 40, 20, 20);
    
    _category_nameImage.frame = CGRectMake(5, 70, 20, 20);
    
    _timeLabel.frame = CGRectMake(30, 5, INFORVIEW_WIDTH - 140, 30);
//    _timeLabel.backgroundColor = [UIColor lightGrayColor];
    
    _addressLabel.frame = CGRectMake(30, 35, INFORVIEW_WIDTH - 140, 30);
//    _addressLabel.backgroundColor = [UIColor redColor];
    
    _category_nameLabel.frame = CGRectMake(30, 65, INFORVIEW_WIDTH - 140, 30);
//    _category_nameLabel.backgroundColor = [UIColor yellowColor];
    
    _image.frame = CGRectMake(INFORVIEW_WIDTH - 100, 5, 95, TITLEVIEW_HEIGHT - 50 - 10);
//    _image.backgroundColor = [UIColor cyanColor];
    
    _interestLabel.frame = CGRectMake(10, INFORVIEW_HEIGHT - 35, 60, 25);
//    _interestLabel.backgroundColor = [UIColor cyanColor];
    
    _interestNumLabel.frame = CGRectMake(_interestLabel.frame.size.width, INFORVIEW_HEIGHT - 35, 50, 25);
//    _interestNumLabel.backgroundColor = [UIColor greenColor];
    
    _joinLabel.frame = CGRectMake(10 + _interestNumLabel.frame.size.width + _interestLabel.frame.size.width, INFORVIEW_HEIGHT - 35, 60, 25);
//    _joinLabel.backgroundColor = [UIColor groupTableViewBackgroundColor];
    
    _joinNumLabel.frame = CGRectMake(10 + _interestNumLabel.frame.size.width + _interestLabel.frame.size.width + _joinLabel.frame.size.width, INFORVIEW_HEIGHT - 35, 50, 25);
//    _joinNumLabel.backgroundColor = [UIColor blueColor];
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
